package com.bidevalution.controller.api;

import com.bidevalution.business.service.BeNoticeDataService;
import com.bidevalution.business.service.BeSectionDecryptService;
import com.bidevalution.business.service.BeSectionSignService;
import com.bidevalution.dao.entity.BeSectionDecrypt;
import com.qtp.common.core.ContextHolderUtils;
import com.qtp.core.model.Paging;
import com.qtp.core.util.DateUtil;
import lombok.extern.log4j.Log4j2;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author shenh@glodon.com
 * @date 2019-06-05 10:39
 */
@Log4j2
@RestController
@RequestMapping("/beNoticeDataController")
public class BeNoticeDataController extends BaseController {
    @Autowired
    private BeNoticeDataService beNoticeDataService;
    @Autowired
    private BeSectionDecryptService beSectionDecryptService;
    @Autowired
    private BeSectionSignService beSectionSignService;
    private Logger logger = Logger.getLogger(getClass());
    /**
     * 解密结束（解密时间为0）
     * @param sectionId 标段Id
     * @return
     */
    @RequestMapping(value = "/addC6", method = RequestMethod.POST)
    @ResponseBody
    public void addC6(@RequestParam("sectionId")String sectionId) {
        try {
            int finishDecryptCount = beSectionDecryptService.getDecryptedCount(sectionId).intValue();
            int signCount = beSectionSignService.querySignCount(sectionId).intValue();
            int unFinishDecryptCount = signCount - finishDecryptCount;
            beNoticeDataService.addC6(sectionId, DateUtil.now(), signCount, finishDecryptCount, unFinishDecryptCount);
        } catch (Exception e) {
        	logger.error(e.getMessage());
        }
    }

    /**
     * 提前解密完成时（所有签到单位均解密完成）
     * @param sectionId 标段Id
     * @return
     */
    @RequestMapping(value = "/addC7", method = RequestMethod.POST)
    @ResponseBody
    public void addC7(@RequestParam("sectionId")String sectionId) {
        try {
            int finishDecryptCount = beSectionDecryptService.getDecryptedCount(sectionId).intValue();
            int signCount = beSectionSignService.querySignCount(sectionId).intValue();
            beNoticeDataService.addC7(sectionId, DateUtil.now(), signCount, finishDecryptCount);
        } catch (Exception e) {
        	logger.error(e.getMessage());
        }
    }


    /**
     * 参数抽取结束后
     * @param sectionId 标段Id
     * @return
     */
    @RequestMapping(value = "/addC10", method = RequestMethod.POST)
    @ResponseBody
    public void addC10(@RequestParam("sectionId")String sectionId) {
        try {
            beNoticeDataService.addC10(sectionId, DateUtil.now());
        } catch (Exception e) {
        	logger.error(e.getMessage());
        }
    }

    /**
     * 评审结果显示后
     * @param sectionId 标段Id
     * @return
     */
    @RequestMapping(value = "/addC12", method = RequestMethod.POST)
    @ResponseBody
    public void addC12(@RequestParam("sectionId")String sectionId) {
        try {
            beNoticeDataService.addC12(sectionId, DateUtil.now());
        } catch (Exception e) {
        	logger.error(e.getMessage());
        }
    }
}
